package com.wenyu.wenyuyuedu.adapter.circleAdapter;

import android.content.Context;
import android.content.Intent;
import android.text.Html;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.wenyu.wenyuyuedu.R;
import com.wenyu.wenyuyuedu.activity.homepage.CircleAttentionActivity;
import com.wenyu.wenyuyuedu.bean.circle.CircleDetailBean;
import com.wenyu.wenyuyuedu.utils.ListViewAndListView;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2017/3/27.
 * 圈子详情页条目的--一级评论
 */

public class CircleDetailListOneAdapter extends BaseAdapter {
    private List<CircleDetailBean.InfoBeanX.InfoBean.PCommentBean> pComment = new ArrayList<>();
    private Context context;
    public int positiion;
    private Intent intent = new Intent();
    private ArrayList<CircleDetailBean.InfoBeanX.InfoBean> mDataList ;
    public CircleDetailListOneAdapter(Context context,int position,ArrayList<CircleDetailBean.InfoBeanX.InfoBean> mDataList) {
        this.context = context;
        this.positiion = position;
        this.mDataList = mDataList;
    }

    @Override
    public int getCount() {
        return pComment.size();
    }

    @Override
    public Object getItem(int i) {
        return null;
    }

    @Override
    public long getItemId(int i) {
        return 0;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        MyCircleDetailViewHolder holder = null;
        if (view == null) {
            holder = new MyCircleDetailViewHolder();
            view = View.inflate(context, R.layout.circledetail_listone_item, null);
            holder.tv_listone_name = (TextView) view.findViewById(R.id.tv_listone_name);
            holder.circle_second_listview = (ListViewAndListView) view.findViewById(R.id.circle_second_listview);
            view.setTag(holder);
        } else {
            holder = (MyCircleDetailViewHolder) view.getTag();
        }
        if (pComment != null) {
            CircleDetailBean.InfoBeanX.InfoBean.PCommentBean pCommentBean = pComment.get(i);
            String comment_name = pCommentBean.getComment_name();
            final String content = pCommentBean.getContent();
            holder.tv_listone_name.setText(Html.fromHtml("<b>" + "<font color = '#576b95'>" + comment_name + ":" + "</font>" + "</b>" + "<font color='#000000'>" + content + "</font>"));
            List<CircleDetailBean.InfoBeanX.InfoBean.PCommentBean.SonCommentBean> son_comment = pCommentBean.getSon_comment();
            CircleSecondCommentAdapter adapter = new CircleSecondCommentAdapter(context);
            holder.circle_second_listview.setAdapter(adapter);
            adapter.addAll(son_comment);
            holder.tv_listone_name.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    CircleDetailBean.InfoBeanX.InfoBean infoBean = mDataList.get(positiion);
                    intent.setClass(context, CircleAttentionActivity.class);
                    /*对应帖子的id*/
                    String id = infoBean.getId();
                    intent.putExtra("allattentionid", id);
                    /*创建帖子的uid*/
                    String uid = infoBean.getUid();
                    intent.putExtra("allattentionnicknameuid", uid);
                    /*发帖人的昵称*/
                    String nickname = infoBean.getMember().getNickname();
                    intent.putExtra("allattentionnickname", nickname);
                    context.startActivity(intent);
                }
            });
            holder.circle_second_listview.setOnItemClickListener(new AdapterView.OnItemClickListener() {
                @Override
                public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
                    CircleDetailBean.InfoBeanX.InfoBean infoBean = mDataList.get(positiion);
                    intent.setClass(context, CircleAttentionActivity.class);
                    /*对应帖子的id*/
                    String id = infoBean.getId();
                    intent.putExtra("allattentionid", id);
                    /*创建帖子的uid*/
                    String uid = infoBean.getUid();
                    intent.putExtra("allattentionnicknameuid", uid);
                    /*发帖人的昵称*/
                    String nickname = infoBean.getMember().getNickname();
                    intent.putExtra("allattentionnickname", nickname);
                    context.startActivity(intent);
                }
            });
        }

        return view;
    }

    class MyCircleDetailViewHolder {
        TextView tv_listone_name;
        ListViewAndListView circle_second_listview;
    }

    public void addAll(List<CircleDetailBean.InfoBeanX.InfoBean.PCommentBean> pComment) {
        if (pComment != null) {
            this.pComment = pComment;
            notifyDataSetChanged();
        }
    }
}
